﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Specialized;
using System.IO;
using Vms.DB;
using Vms.Business;

public partial class bongda : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DB m_db = new DB();
        Util m_util = new Util();
        WriteFile wf = new WriteFile();
        Util.TSession m_tSession = new Util.TSession();
        try
        {
            m_tSession.UserMSISDN = m_util.GetHeaderValue(Request.Headers, "User-MSISDN");
            m_tSession.User_ID = m_util.GetHeaderValue(Request.Headers, "User-UID");
            m_tSession.ServiceList = "1";
            m_tSession.KeyPress = "1";
            m_tSession.SessionID = "";
            m_tSession.IP = "";
            m_db.UpdateReQuestTbl(m_tSession);
            string str = "";
            int service_id = 0;
            str = "<?xml version='1.0' encoding='ISO-8859-1'?>" +
                   "<!DOCTYPE pages SYSTEM 'cellflash.dtd'>" +
                   "<pages descr='Samis'>" +
                   "<page> ";
            if (Request.Params["sid"] != null)
            {
                service_id = Int32.Parse(Request.Params["sid"]);
            }
            else
            {
                service_id = Int32.Parse(Request.Params["cid"]);
                DataSet ds = new DataSet();
                ds = m_db.GetServiceByPage(service_id);
                DataTable dtb = new DataTable();
                dtb = ds.Tables[0].Clone();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    dtb.Rows.Add(ds.Tables[0].Rows[i].ItemArray);
                }
                foreach (DataRow dr in dtb.Rows)
                {
                    str += "<a href='" + dr["URL"].ToString().Trim() + dr["Service_ID"].ToString() + "'>" + dr["Text"].ToString().Trim() + "(" + dr["Cost"].ToString() + ")</a><br/>";
                }
            }

            if (service_id == 11)
            {
                //Ket qua
                int cost = m_db.GetCostByService(service_id);
                // "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=0'>Cac tran dang dien ra</a><br/>" +
                str += "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=2'>Ngoai Hang Anh</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=31'>Vo Dich Italia</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=243'>Vo Dich Tay Ban Nha</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=32'>Vo Dich Duc</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=206'>Vo Dich Phap</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=1'>Cup C1 chau Au</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=9'>Cup EuropaLeague</a><br/>" +
                   "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongDa&t=0&re=0&i=000001:0000000011:KQBD&d=BongDa_KetQua.aspx?giaidauid=-1'>Cac Giai Khach</a><br/>";
            }
            else if (service_id == 12)
            {
                //Ti le
                int cost = m_db.GetCostByService(service_id);
                //"<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BDTL&t=0&re=0&i=000001:0000000011:KQTL&d=BongDa_Tile.aspx?service_id=" + service_id.ToString() + "&giaidauid=1'>Cac tran dang dien ra</a><br/>" +
                str += "Ti Le <br/> <a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:KQTL&d=BongDa_Tile.aspx?giaidauid=2'>Ngoai Hang Anh</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=31'>Vo Dich Italia</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=243'>Vo Dich Tay Ban Nha</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=32'>Vo Dich Duc</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=206'>Vo Dich Phap</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=1'>Cup C1 chau Au</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=9'>Cup EuropaLeague</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaTL&t=0&re=0&i=000001:0000000012:BDTL&d=BongDa_Tile.aspx?giaidauid=-1'>Cac Giai Khach</a><br/>";
            }
            else if (service_id == 13)
            {
                //Lich Thi Dau
                int cost = m_db.GetCostByService(service_id);
                //"<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=Ma dich vu&t=0&re=0&i=Tru cuoc kqbongda850**&d=BongDa_KetQua.aspx?service_id=" + service_id.ToString() + "&giaidauid=1'>Cac tran dang dien ra</a><br/>" +
                str += "LTD <br/> <a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=2'>Ngoai Hang Anh</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=31'>Vo Dich Italia</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=243'>Vo Dich Tay Ban Nha</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=32'>Vo Dich Duc</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=206'>Vo Dich Phap</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=1'>Cup C1 chau Au</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=9'>Cup EuropaLeague</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaLTD&t=0&re=0&i=000001:0000000013:BDLTD&d=BongDa_LichThiDau.aspx?giaidauid=-1'>Cac Giai Khach</a><br/>";
            }
            else if (service_id == 14)
            {
                //BXH
                //Ket qua
                int cost = m_db.GetCostByService(service_id);
                //"<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=Ma dich vu&t=0&re=0&i=Tru cuoc kqbongda850**&d=BongDa_KetQua.aspx?service_id=" + service_id.ToString() + "&giaidauid=1'>Cac tran dang dien ra</a><br/>" +
                str += "BXH <br/> <a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=2'>Ngoai Hang Anh</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=31'>Vo Dich Italia</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=243'>Vo Dich Tay Ban Nha</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=32'>Vo Dich Duc</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=206'>Vo Dich Phap</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=1'>Cup C1 chau Au</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=9'>Cup EuropaLeague</a><br/>" +
                    "<a href='/850/sys/bill?a=" + cost.ToString() + "&b=0&c=BongdaBXH&t=0&re=0&i=000001:0000000014&d=BongDa_BXH.aspx?giaidauid=-1'>Cac Giai Khach</a><br/>";
            }
            str += "</page>" +
                  "</pages>";

            Response.ClearHeaders();
            Response.AddHeader("content-type", "text/xml");
            //Response.Write(str);
            wf.WriteStreamFile(str);
            Response.End();
        }
        catch (Exception ex)
        {
            wf.WriteError(ex.ToString());
        }
    }
}